package com.application.Activity;

import com.application.Controller.ActivityController;
import com.application.Controller.NetworkController;

import android.app.AlertDialog;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.GetChars;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

public class MESApplication extends Application{
	 private static Context context;

	    public void onCreate(){
	        super.onCreate();
	        MESApplication.context = getApplicationContext();
	    }

	    public static Context getAppContext() {
	        return MESApplication.context;
	    }
	    public static int getWidth(){
	    	WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	    	Display display = wm.getDefaultDisplay();
	    	return display.getWidth();
	    }
	    public static int getHeight(){
	    	WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
	    	Display display = wm.getDefaultDisplay();
	    	return display.getHeight();
	    }
	    public static void exitApp(){
	    	android.os.Process.killProcess(android.os.Process.myPid());
	    	System.exit(0);
	    }
	    public static void displayNotification(String tickerText, String contentTitle, String contentText) {

			Log.i("Phu","trong displayNotification:   "+tickerText+" : "+contentText+" : "+contentTitle);
			
			Intent intent = new Intent(getAppContext(), frmNotificationMoiVaoNhom.class);
			intent.putExtra("ID", 1);
			intent.putExtra("tickerText", tickerText);
			intent.putExtra("contentTitle", contentTitle);
			intent.putExtra("contentText", contentText);
			
		
			PendingIntent pendingIntent = PendingIntent.getActivity(getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
			NotificationManager notiManager = (NotificationManager) getAppContext().getSystemService(NOTIFICATION_SERVICE);
			Notification notif = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());
			String[] m = contentText.split("#~");
			notif.setLatestEventInfo(getAppContext(), m[0] + " mời bạn vào nhóm!", contentTitle, pendingIntent);
			notif.flags|=Notification.FLAG_AUTO_CANCEL;
			notif.when=1;
			notiManager.notify(1, notif);
			
		}
//	    public static void showLogoutTeacher(){
//	    	Log.v("Phu","vao ham showLogoutTeacher MES");
//	    	AlertDialog dlg = new AlertDialog.Builder(ActivityController.getPeerActivity()).setTitle("Thông báo")
//			.setCancelable(false).setMessage("Giáo viên đã rời khỏi hệ thống.")//.setIcon(R.drawable.img_dialog)
//			
//			.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//			
//				@Override
//				public void onClick(DialogInterface dialog, int which) {
//					Log.v("Phu","vao onclick");
//					NetworkController.peerRelease();
//					Log.v("PEERDROID","Đã Thoát khỏi chương trình");
//					ActivityController.getPeerActivity().finish();
//					System.exit(0);
//				}
//			}).create();
//			Log.v("Phu","1");
//			dlg.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(0, 255, 255, 255)));
//			Log.v("Phu","2");
//			dlg.show();
//			
//			Log.v("Phu","3");
//		}
	    
}
